/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.inventory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.inventory.AdjMst;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class AdjMstListTM extends AbstractTableModel{
    static protected String[] columnNames = { "NO.", "NO.TRANSAKSI", "TANGGAL","KETERANGAN","ID" };
    static protected Class<?>[] columnTypes = { Integer.class, String.class, Date.class, String.class,Integer.class };
    private List<AdjMst> data;

    public AdjMstListTM() {
        this(new ArrayList<AdjMst>(0));
    }

    public AdjMstListTM(List<AdjMst> data) {
        this.data = data;
    }
    
    
    
    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
       return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
         switch (columnIndex) {
            case 0: return rowIndex+1;
            case 1: return data.get(rowIndex).getTransNum();
            case 2: return data.get(rowIndex).getTransDate();
            case 3: return data.get(rowIndex).getNotes();
            case 4: return data.get(rowIndex).getId();
            default:return null;
         }
    }
    
     @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Class<?> getColumnClass(int column) {
        return columnTypes[column];
    }
    
     public AdjMst get(int index) {
        return data.get(index);
    }

    public void add(AdjMst product) {
        data.add(product);
        fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
    }

    public void remove(int index) {
        data.remove(index);
        fireTableRowsDeleted(index, index);
    }

    public void set(int index, AdjMst product) {
        data.set(index, product);
        fireTableRowsUpdated(index, index);
    }

    public void clear() {
        data.clear();
        fireTableDataChanged();
    }

    public void add(Collection<AdjMst> products) {
        data.addAll(products);
        fireTableRowsInserted(getRowCount() - (products.size()), getRowCount() - 1);
    }
    
}
